import { useIntersectionObserver } from '@vueuse/core'
export default {
  install (app) {
    // vue2
    // Vue.directive('指令名', {
    //   inserted (el, binding) {
    //     // 执行逻辑
    //   }
    // })
    app.directive('imgLazy', {
      mounted (el, binding) {
        // console.log('el', el)
        const { stop } = useIntersectionObserver(
          // 需要的dom 或者是组件
          el,
          ([{ isIntersecting }], observerElement) => {
            // console.log('我出现在可视区域了', isIntersecting)
            if (isIntersecting) {
              // console.log('binding', binding)
              el.src = binding.value
              stop()
            }
          }
        )
      }
    })
  }
}
